package b3.widget.home.town
{
	import b3.model.*;
	import b3.net.*;
	import b3.scene.home.*;
	import b3.util.*;
	import b3.widget.basic.*;
	
	import com.greensock.*;
	
	import flash.events.*;
	import flash.display.*;
	import flash.text.*;
	import flash.filters.*;
	
	public class HomeIcon extends BasicWidget
	{
		private var iconImg:ImgSwitchIcon;
		private var hideFlag:Boolean;
		
		public function HomeIcon()
		{
			super();
			var HomeIcon0:Class = ResourceHelper.getInstance().getClassByName("ExitIcon0");
			var HomeIcon1:Class = ResourceHelper.getInstance().getClassByName("ExitIcon1");
			iconImg = new ImgSwitchIcon(HomeIcon0, HomeIcon1, "回家", 1, true);
			addChild(iconImg);
			this.anchor = ANCHOR_RIGHT_BOTTOM;
			this.x = -100;
			this.y = -150;
			hideFlag = true;
			iconImg.x = width + 100;
			this.addEventListener(MouseEvent.CLICK, onMouseClick);
			this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}
		
		private function onMouseOver(event:MouseEvent):void
		{
			var container:Sprite = new Sprite();		
			//提示图标
			var OperationAttack:Class = ResourceHelper.getInstance().getClassByName("ExitIcon0");
			var tipIcon:Sprite = new OperationAttack();
			tipIcon.height = 60;
			tipIcon.scaleX = tipIcon.scaleY;
			tipIcon.x = 10;
			tipIcon.y = 0;
			container.addChild(tipIcon);
			//提示信息
			var tipText:TextField = new TextField();
			tipText.selectable = false;
			tipText.autoSize = TextFieldAutoSize.LEFT;
			tipText.defaultTextFormat = new TextFormat("微软雅黑", 25, 0xFFFFFF, true);
			tipText.filters = [new GlowFilter(0x00AAFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			tipText.text = "点击回到自己的城市";
			tipText.x = 75;
			tipText.y = 12;
			container.addChild(tipText);
			HomeScene.getInstance().centerInfoPane.showInfo(container);
		}
		
		private function onMouseOut(event:MouseEvent):void
		{
			HomeScene.getInstance().centerInfoPane.clear();
		}
		
		public function hide():void
		{
			hideFlag = true;
			TweenLite.to(iconImg, 2, {x: iconImg.width + 100});
		}
		
		public function show():void
		{
			hideFlag = false;
			TweenLite.to(iconImg, 2, {x: 0});
		}
		
		private function onMouseClick(event:Event):void
		{
			HomeScene.getInstance().loadPlayer(PlayerManager.getInstance().me);
		}
		
	}
}